//
// NeL - bindings
// Copyright (C) 2010 Naush
//
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as
//published by the Free Software Foundation, either version 3 of the
//License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Affero General Public License for more details.
//
//You should have received a copy of the GNU Affero General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

package org.ryzom.nel.misc;

public class CBitmap {
  private long swigCPtr;
  protected boolean swigCMemOwn;

  public CBitmap(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  public static long getCPtr(CBitmap obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        nelmiscJNI.delete_CBitmap(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public void setPixelFormat(CBitmap.TType value) {
    nelmiscJNI.CBitmap_PixelFormat_set(swigCPtr, this, value.swigValue());
  }

  public static SWIGTYPE_p_unsigned_int getBitPerPixels() {
    long cPtr = nelmiscJNI.CBitmap_bitPerPixels_get();
    return (cPtr == 0) ? null : new SWIGTYPE_p_unsigned_int(cPtr, false);
  }

  public static long getDXTC1HEADER() {
    return nelmiscJNI.CBitmap_DXTC1HEADER_get();
  }

  public static long getDXTC3HEADER() {
    return nelmiscJNI.CBitmap_DXTC3HEADER_get();
  }

  public static long getDXTC5HEADER() {
    return nelmiscJNI.CBitmap_DXTC5HEADER_get();
  }

  public CBitmap() {
    this(nelmiscJNI.new_CBitmap(), true);
  }

  public void swap(CBitmap other) {
    nelmiscJNI.CBitmap_swap(swigCPtr, this, CBitmap.getCPtr(other), other);
  }

  public short load(IStream f, long mipMapSkip) {
    return nelmiscJNI.CBitmap_load__SWIG_0(swigCPtr, this, IStream.getCPtr(f), f, mipMapSkip);
  }

  public short load(IStream f) {
    return nelmiscJNI.CBitmap_load__SWIG_1(swigCPtr, this, IStream.getCPtr(f), f);
  }

  public static void loadSize(IStream f, SWIGTYPE_p_unsigned_int width, SWIGTYPE_p_unsigned_int height) {
    nelmiscJNI.CBitmap_loadSize__SWIG_0(IStream.getCPtr(f), f, SWIGTYPE_p_unsigned_int.getCPtr(width), SWIGTYPE_p_unsigned_int.getCPtr(height));
  }

  public static void loadSize(String path, SWIGTYPE_p_unsigned_int retWidth, SWIGTYPE_p_unsigned_int retHeight) {
    nelmiscJNI.CBitmap_loadSize__SWIG_1(path, SWIGTYPE_p_unsigned_int.getCPtr(retWidth), SWIGTYPE_p_unsigned_int.getCPtr(retHeight));
  }

  public void makeDummy() {
    nelmiscJNI.CBitmap_makeDummy(swigCPtr, this);
  }

  public void makeNonPowerOf2Dummy() {
    nelmiscJNI.CBitmap_makeNonPowerOf2Dummy(swigCPtr, this);
  }

  public SWIGTYPE_p_CObjectVectorT_unsigned_char_t getPixels(long numMipMap) {
    return new SWIGTYPE_p_CObjectVectorT_unsigned_char_t(nelmiscJNI.CBitmap_getPixels__SWIG_0(swigCPtr, this, numMipMap), false);
  }

  public SWIGTYPE_p_CObjectVectorT_unsigned_char_t getPixels() {
    return new SWIGTYPE_p_CObjectVectorT_unsigned_char_t(nelmiscJNI.CBitmap_getPixels__SWIG_1(swigCPtr, this), false);
  }

  public void unattachPixels(SWIGTYPE_p_CObjectVectorT_unsigned_char_t mipmapDestArray, long maxMipMapCount) {
    nelmiscJNI.CBitmap_unattachPixels__SWIG_0(swigCPtr, this, SWIGTYPE_p_CObjectVectorT_unsigned_char_t.getCPtr(mipmapDestArray), maxMipMapCount);
  }

  public void unattachPixels(SWIGTYPE_p_CObjectVectorT_unsigned_char_t mipmapDestArray) {
    nelmiscJNI.CBitmap_unattachPixels__SWIG_1(swigCPtr, this, SWIGTYPE_p_CObjectVectorT_unsigned_char_t.getCPtr(mipmapDestArray));
  }

  public boolean convertToType(CBitmap.TType type) {
    return nelmiscJNI.CBitmap_convertToType(swigCPtr, this, type.swigValue());
  }

  public CBitmap.TType getPixelFormat() {
    return CBitmap.TType.swigToEnum(nelmiscJNI.CBitmap_getPixelFormat(swigCPtr, this));
  }

  public long getWidth(long numMipMap) {
    return nelmiscJNI.CBitmap_getWidth__SWIG_0(swigCPtr, this, numMipMap);
  }

  public long getWidth() {
    return nelmiscJNI.CBitmap_getWidth__SWIG_1(swigCPtr, this);
  }

  public long getHeight(long numMipMap) {
    return nelmiscJNI.CBitmap_getHeight__SWIG_0(swigCPtr, this, numMipMap);
  }

  public long getHeight() {
    return nelmiscJNI.CBitmap_getHeight__SWIG_1(swigCPtr, this);
  }

  public long getSize(long numMipMap) {
    return nelmiscJNI.CBitmap_getSize__SWIG_0(swigCPtr, this, numMipMap);
  }

  public long getSize() {
    return nelmiscJNI.CBitmap_getSize__SWIG_1(swigCPtr, this);
  }

  public long getMipMapCount() {
    return nelmiscJNI.CBitmap_getMipMapCount(swigCPtr, this);
  }

  public long computeNeededMipMapCount() {
    return nelmiscJNI.CBitmap_computeNeededMipMapCount(swigCPtr, this);
  }

  public void rotateCCW() {
    nelmiscJNI.CBitmap_rotateCCW(swigCPtr, this);
  }

  public void buildMipMaps() {
    nelmiscJNI.CBitmap_buildMipMaps(swigCPtr, this);
  }

  public void releaseMipMaps() {
    nelmiscJNI.CBitmap_releaseMipMaps(swigCPtr, this);
  }

  public void reset(CBitmap.TType type) {
    nelmiscJNI.CBitmap_reset__SWIG_0(swigCPtr, this, type.swigValue());
  }

  public void reset() {
    nelmiscJNI.CBitmap_reset__SWIG_1(swigCPtr, this);
  }

  public void resample(int nNewWidth, int nNewHeight) {
    nelmiscJNI.CBitmap_resample(swigCPtr, this, nNewWidth, nNewHeight);
  }

  public void resize(int nNewWidth, int nNewHeight, CBitmap.TType newType, boolean resetTo0) {
    nelmiscJNI.CBitmap_resize__SWIG_0(swigCPtr, this, nNewWidth, nNewHeight, newType.swigValue(), resetTo0);
  }

  public void resize(int nNewWidth, int nNewHeight, CBitmap.TType newType) {
    nelmiscJNI.CBitmap_resize__SWIG_1(swigCPtr, this, nNewWidth, nNewHeight, newType.swigValue());
  }

  public void resize(int nNewWidth, int nNewHeight) {
    nelmiscJNI.CBitmap_resize__SWIG_2(swigCPtr, this, nNewWidth, nNewHeight);
  }

  public void resizeMipMap(long numMipMap, int nNewWidth, int nNewHeight, boolean resetTo0) {
    nelmiscJNI.CBitmap_resizeMipMap__SWIG_0(swigCPtr, this, numMipMap, nNewWidth, nNewHeight, resetTo0);
  }

  public void resizeMipMap(long numMipMap, int nNewWidth, int nNewHeight) {
    nelmiscJNI.CBitmap_resizeMipMap__SWIG_1(swigCPtr, this, numMipMap, nNewWidth, nNewHeight);
  }

  public void setMipMapCount(long mmc) {
    nelmiscJNI.CBitmap_setMipMapCount(swigCPtr, this, mmc);
  }

  public boolean writeTGA(IStream f, long d, boolean upsideDown) {
    return nelmiscJNI.CBitmap_writeTGA__SWIG_0(swigCPtr, this, IStream.getCPtr(f), f, d, upsideDown);
  }

  public boolean writeTGA(IStream f, long d) {
    return nelmiscJNI.CBitmap_writeTGA__SWIG_1(swigCPtr, this, IStream.getCPtr(f), f, d);
  }

  public boolean writeTGA(IStream f) {
    return nelmiscJNI.CBitmap_writeTGA__SWIG_2(swigCPtr, this, IStream.getCPtr(f), f);
  }

  public boolean writePNG(IStream f, long d) {
    return nelmiscJNI.CBitmap_writePNG__SWIG_0(swigCPtr, this, IStream.getCPtr(f), f, d);
  }

  public boolean writePNG(IStream f) {
    return nelmiscJNI.CBitmap_writePNG__SWIG_1(swigCPtr, this, IStream.getCPtr(f), f);
  }

  public boolean writeJPG(IStream f, short quality) {
    return nelmiscJNI.CBitmap_writeJPG__SWIG_0(swigCPtr, this, IStream.getCPtr(f), f, quality);
  }

  public boolean writeJPG(IStream f) {
    return nelmiscJNI.CBitmap_writeJPG__SWIG_1(swigCPtr, this, IStream.getCPtr(f), f);
  }

  public void loadGrayscaleAsAlpha(boolean loadAsAlpha) {
    nelmiscJNI.CBitmap_loadGrayscaleAsAlpha(swigCPtr, this, loadAsAlpha);
  }

  public boolean isGrayscaleAsAlpha() {
    return nelmiscJNI.CBitmap_isGrayscaleAsAlpha(swigCPtr, this);
  }

  public boolean blit(CBitmap src, int x, int y) {
    return nelmiscJNI.CBitmap_blit__SWIG_0(swigCPtr, this, CBitmap.getCPtr(src), src, x, y);
  }

  public void blit(CBitmap src, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY) {
    nelmiscJNI.CBitmap_blit__SWIG_1(swigCPtr, this, CBitmap.getCPtr(src), src, srcX, srcY, srcWidth, srcHeight, destX, destY);
  }

  public CRGBAF getColor(float x, float y) {
    return new CRGBAF(nelmiscJNI.CBitmap_getColor__SWIG_0(swigCPtr, this, x, y), true);
  }

  public CRGBAF getColor(float x, float y, boolean tileU, boolean tileV) {
    return new CRGBAF(nelmiscJNI.CBitmap_getColor__SWIG_1(swigCPtr, this, x, y, tileU, tileV), true);
  }

  public CRGBA getPixelColor(int x, int y, long numMipMap) {
    return new CRGBA(nelmiscJNI.CBitmap_getPixelColor__SWIG_0(swigCPtr, this, x, y, numMipMap), true);
  }

  public CRGBA getPixelColor(int x, int y) {
    return new CRGBA(nelmiscJNI.CBitmap_getPixelColor__SWIG_1(swigCPtr, this, x, y), true);
  }

  public void flipH() {
    nelmiscJNI.CBitmap_flipH(swigCPtr, this);
  }

  public void flipV() {
    nelmiscJNI.CBitmap_flipV(swigCPtr, this);
  }

  public void rot90CW() {
    nelmiscJNI.CBitmap_rot90CW(swigCPtr, this);
  }

  public void rot90CCW() {
    nelmiscJNI.CBitmap_rot90CCW(swigCPtr, this);
  }

  public void blend(CBitmap Bm0, CBitmap Bm1, long factor, boolean inputBitmapIsMutable) {
    nelmiscJNI.CBitmap_blend__SWIG_0(swigCPtr, this, CBitmap.getCPtr(Bm0), Bm0, CBitmap.getCPtr(Bm1), Bm1, factor, inputBitmapIsMutable);
  }

  public void blend(CBitmap Bm0, CBitmap Bm1, long factor) {
    nelmiscJNI.CBitmap_blend__SWIG_1(swigCPtr, this, CBitmap.getCPtr(Bm0), Bm0, CBitmap.getCPtr(Bm1), Bm1, factor);
  }

  public void getData(SWIGTYPE_p_p_unsigned_char extractData) {
    nelmiscJNI.CBitmap_getData(swigCPtr, this, SWIGTYPE_p_p_unsigned_char.getCPtr(extractData));
  }

  public void getDibData(SWIGTYPE_p_p_unsigned_char extractData) {
    nelmiscJNI.CBitmap_getDibData(swigCPtr, this, SWIGTYPE_p_p_unsigned_char.getCPtr(extractData));
  }

  public CBitmap assign(CBitmap from) {
    return new CBitmap(nelmiscJNI.CBitmap_assign(swigCPtr, this, CBitmap.getCPtr(from), from), false);
  }

  public final static class TType {
    public final static TType RGBA = new TType("RGBA", nelmiscJNI.CBitmap_RGBA_get());
    public final static TType Luminance = new TType("Luminance");
    public final static TType Alpha = new TType("Alpha");
    public final static TType AlphaLuminance = new TType("AlphaLuminance");
    public final static TType DXTC1 = new TType("DXTC1");
    public final static TType DXTC1Alpha = new TType("DXTC1Alpha");
    public final static TType DXTC3 = new TType("DXTC3");
    public final static TType DXTC5 = new TType("DXTC5");
    public final static TType DsDt = new TType("DsDt");
    public final static TType ModeCount = new TType("ModeCount");
    public final static TType DonTKnow = new TType("DonTKnow", nelmiscJNI.CBitmap_DonTKnow_get());

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static TType swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + TType.class + " with value " + swigValue);
    }

    private TType(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private TType(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private TType(String swigName, TType swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static TType[] swigValues = { RGBA, Luminance, Alpha, AlphaLuminance, DXTC1, DXTC1Alpha, DXTC3, DXTC5, DsDt, ModeCount, DonTKnow };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

}
